﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SFWS.XHandler.Core;
using JKF.Substructure;
using JKF.Entities.Model;
using JKF.BusinessLayer.BLL;

using JKF.DataModule.SqlServerDAL;
using JKF.BusinessLayer;
using JKF.Entities;
using System.Data;
using JKF.DataModule;

namespace JKF.HandlerLayer.Sys
{
    public class SysLogHandler : AHttpHandler
    {
        public override void ProcessRequest()
        {
            try
            {
                this.HandleRequest(Utils.GetActionName);
            }
            catch (Exception ex)
            {
                //将错误抛到客户端(以Json格式)
                Utils.ToClient(true, ex.Message);
                AppLogger.Log(ex.Message, ex);  //写日志
            }
        }

        /// <summary>
        /// 积分查询
        /// </summary>
        public void LogSearch()
        {
            bllSYS_LOG sysLog = new bllSYS_LOG();
            var obj = new PagerList();

            int pageCount = 0;
            int rowCount = 0;
            obj.Entity = from a in sysLog.LogSearch(P("searchItem"), P("matchWay"), P("keyword"), P("DATA_START"), P("DATA_END"), P("MODULE_NAME"), P("PageIndex").ToInt32(), P("PageSize").ToInt32(), ref pageCount, ref rowCount).AsEnumerable()
                         select new
                         {
                             LOG_KEY = a.Field<Guid>("LOG_KEY").ToString(),
                             MODULE_NAME = a.Field<string>("MODULE_NAME"),
                             TABLE_NAME = a.Field<string>("TABLE_NAME"),
                             PRIMARY_KEY = a.Field<string>("PRIMARY_KEY"),
                             LOG_CONTENT = a.Field<string>("LOG_CONTENT"),
                             OPERATION_TYPE = a.Field<string>("OPERATION_TYPE"),
                             IP = a.Field<string>("IP"),
                             BROWSER = a.Field<string>("BROWSER"),
                             DATE_CREATE = a.Field<DateTime>("DATE_CREATE").ToString(),
                             ACCOUNT = a.Field<string>("ACCOUNT")
                         };

            obj.RowCount = rowCount;
            obj.PageCount = pageCount;
            ResponseJsonObject = obj;
        }
    }
}
